package com.fh.shop.api.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    @Bean
    public DirectExchange MailDirectEx(){
        return new DirectExchange(MQConstant.Mail.EX);
    }
    @Bean
    public Queue mailQueue(){
        return new Queue(MQConstant.Mail.QUEUE);
    }
    @Bean
    public Binding mailBinding(){
        return BindingBuilder.bind(mailQueue()).to(MailDirectEx()).with(MQConstant.Mail.ROUTE_KEY);
    }

    //-------------------------------------

    @Bean
    public FanoutExchange PayFanoutExchange(){
        return new FanoutExchange(MQConstant.Pay.EX);
    }
    @Bean
    public Queue scoreQueue(){
        return new Queue(MQConstant.Pay.QUEUE_SCORE);
    }
    @Bean
    public Queue saleQueue(){
        return new Queue(MQConstant.Pay.QUEUE_SALE);
    }
    @Bean
    public Binding scoreBinding(){
        return BindingBuilder.bind(scoreQueue()).to(PayFanoutExchange());
    }
    @Bean
    public Binding saleBinding(){
        return BindingBuilder.bind(saleQueue()).to(PayFanoutExchange());
    }



    //--------------------------------------

    // 交换机
    @Bean
    public DirectExchange testDirectEx(){
        return new DirectExchange(MQConstant.Test.EX);
    }
    // 队列
    @Bean
    public Queue testQueue(){
        return new Queue(MQConstant.Test.QUEUE);
    }
    //绑定 同时 指定 路由K
    @Bean
    public Binding redBinding(){
        return BindingBuilder.bind(testQueue()).to(testDirectEx()).with(MQConstant.Test.ROUTE_KEY);
    }

    //----------------------------------------

    @Bean
    public FanoutExchange TestFanoutExchange(){
        return new FanoutExchange(MQConstant.TestFanout.EX);
    }
    @Bean
    public Queue FanoutQueue1(){
        return new Queue(MQConstant.TestFanout.QUEUE1);
    }
    @Bean
    public Queue FanoutQueue2(){
        return new Queue(MQConstant.TestFanout.QUEUE2);
    }
    @Bean
    public Binding FanoutBinding1(){
        return BindingBuilder.bind(FanoutQueue1()).to(TestFanoutExchange());
    }
    @Bean
    public Binding FanoutBinding2(){
        return BindingBuilder.bind(FanoutQueue2()).to(TestFanoutExchange());
    }

}
